package com.epalmpay.controller.spot;

import com.epalmpay.commom.BaseController;
import com.epalmpay.entity.RefundPassword;
import com.epalmpay.entity.Ticket;
import com.epalmpay.entity.TradeOffline;
import com.epalmpay.service.spot.ISpotService;
import com.epalmpay.util.Const;
import com.epalmpay.util.payplat.UtilFun;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/1/24.
 */
@Controller
@RequestMapping(value="/merchant/spot")
public class SpotController extends BaseController{

    private static final String MP = "MP";

    @Resource
    private ISpotService spotService;

    /**
     * 获取门票类型列表
     *
     */
    @RequestMapping(value="/getTicketsByGroupId")
    @ResponseBody
    public List getTicketsByGroupId(){
        Ticket ticket = new Ticket();
        ticket.setGroupId(Long.parseLong(getRequest().getParameter("groupid")));
        try {
            return spotService.selectTicketsByGroupId(ticket);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 门票退款
     * @return
     */
    @RequestMapping(value="/refundTicket")
    @ResponseBody
    public Map refundTicket() {
        Map result = new HashMap();

        String orderno = getRequest().getParameter("orderno");
        TradeOffline to = new TradeOffline();
        to.setOrderId(orderno);
        try {
            spotService.updateRefundTicket(to);
            result.put("result", "000000");
        }catch (Exception e) {
            e.printStackTrace();
            result.put("result", "000001");
        }
        return result;
    }

    /**
     * 查询退款密码
     * @return
     */
    @RequestMapping(value="/selectRefundById")
    @ResponseBody
    public Map selectRefundById() {
        Map result = new HashMap();

        String password = getRequest().getParameter("password");
        String groupId = getRequest().getParameter("groupId");
        RefundPassword rp = new RefundPassword();
        rp.setGroupId(Long.parseLong(groupId));
        rp.setPassword(password);
        try {
            RefundPassword rrp = spotService.selectRefundById(rp);
            if(rrp != null) {
                result.put("result", "000000");
            } else {
                result.put("result", "000002");
            }
        }catch (Exception e) {
            result.put("result", "000001");
        }
        return result;
    }

    /**
     * 更新退款密码
     * @return
     */
    @RequestMapping(value="/updateRefundPassword")
    @ResponseBody
    public Map updateRefundPassword() {
        Map result = new HashMap();

        String password = getRequest().getParameter("password");
        String groupId = getRequest().getParameter("groupId");
        RefundPassword rp = new RefundPassword();
        rp.setGroupId(Long.parseLong(groupId));
        rp.setPassword(password);
        try {
            spotService.updateRefundPassword(rp);
            result.put("result", "000000");
        }catch (Exception e) {
            result.put("result", "000001");
        }
        return result;
    }

}
